package tcc.board.activity;

import java.io.IOException;
import java.net.UnknownHostException;

import tcc.board.BoardConnection;
import tcc.board.R;
import tcc.board.R.layout;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class BoardInterfaceActivity extends Activity {
	private static final int ACTIVITY_CREATE=0;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    public void connectAction(View view) {
    	Context ctx = getApplicationContext();
    	
    	try {
    		makeSocket();
        	Toast.makeText(ctx, "Connected", Toast.LENGTH_SHORT).show();
        	
        	requestUserInputActivity();
		} catch (UnknownHostException e) {
        	Toast.makeText(ctx, "Unknown Host", Toast.LENGTH_SHORT).show();
		} catch (IOException e) {
        	Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_SHORT).show();
		} catch (Exception e) {
        	Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_SHORT).show();
		}
    }
    
    private void makeSocket() throws UnknownHostException, IOException {
    	//EditText etIp = (EditText) findViewById(R.id.editText_connectionIP);
    	//EditText etPort = (EditText) findViewById(R.id.editText_connectionPort);
    	
    	//String ip = etIp.getText().toString();
    	//int port = Integer.parseInt(etPort.getText().toString());
    	
    	String ip = "192.168.0.1";
    	String port = "4096";
		BoardConnection.getInstance().connect(ip, port);
    }
    
    private void requestUserInputActivity() {
    	Intent controllerActivity = new Intent(this, BoardControllerActivity.class);        	
    	startActivityForResult(controllerActivity, ACTIVITY_CREATE);
    }
}